import baseRequest from "@/axios/baseRequest"
import utils from "../utils/index"

export default {
  startCheckTask(params) {
    return new Promise((resolve, reject) => {
      baseRequest.post("/bigdata-pv-backend/diagtask/manualStartDiagTask", params).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getCompanyList(params) {
    const temParams = utils.jsonToQuery(params)
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/getCompanyList?" + temParams).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getStationByCompany(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/getStationList?companyCode=" + params.companyCode).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getTaskNumberByCompany(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/getTaskList?companyCode=" + params.companyCode + '&stationCode=' + params.stationCode + '&inspectDayStart=' + params.inspectDayStart + '&inspectDayEnd=' + params.inspectDayEnd).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getTaskNumberByCompany1(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/dataResource/getTaskList?companyCode=" + params.companyCode + '&stationCode=' + params.stationCode).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  listInspectTaskCode(params) {
    const temParams = utils.jsonToQuery(params)
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/dataResource/listInspectTaskCode?" + temParams).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getOuterModelList(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/getOuterModelList").then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getTaskLists(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/getTaskList?" + getParamStr(params)).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getOriFileNameList(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/details/getOriFileNameList?" + getParamStr(params)).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  getFilesAndRemark(params) {
    return new Promise((resolve, reject) => {
      baseRequest.get("/bigdata-pv-backend/diagtask/getAllOriFileNameAndRemark?" + getParamStr(params)).then(data => {
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  }
}

let getParamStr = (param) => {
  let str = ''
  for (let key in param) {
    if (param[key]) {
      str += [key] + '=' + param[key] + '&'
    }
  }
  return str
}
